import {request, handleFetchResultNotification, REQUEST_TYPE} from '../../utils';
import {formatMessage} from '../localize';
import stringify from 'Shared/utils/stringify';
const baseUrl = '/afterSales/api/v1';

const getDealerDesc = formatMessage({
    id: 'api.message.getDealerDesc',
    defaultMessage: '查询服务站信息'
});

const getListTreeDesc = formatMessage({
    id: 'api.getListTreeDesc',
    defaultMessage: '查询大区树'
});

const getRegionDesc = formatMessage({
    id: 'api.getRegionDesc',
    defaultMessage: '查询国际区域列表'
});

// 查询服务站
export const getDealers = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dealers/forSubDealer?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealerDesc));
};

// 根据国际区域查询大区
export const getMarketDepartments = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/marketDepartments/forSubDealer?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListTreeDesc));
};

// 查询国际区域列表
export const getRegions = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/areaTileds/forSubDealer?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getRegionDesc));
};


//根据条件查询总代子公司
export const getDealerSimple = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dealers/forSubDealer/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealerDesc));
};
